﻿using System;
using System.Linq;
using System.Collections.Generic;
namespace week4_work2
{
    class Program
    {
        static void Main(string[] args)
        {
            LinqSort Num = new LinqSort();
            foreach (int n in Num.num) {        //随机生成100个数并显示
                Console.Write("  "+n);
            }
            Num.Linqsort();
            Console.WriteLine();
            foreach (int n in Num.num)          //排序（降序）后显示
            {        
                Console.Write("  " + n);
            }
            Console.WriteLine();
            Console.WriteLine("总和Sun:"+Num.LinqSum()+",平均数average:"+Num.averange());
        }
    }
    class LinqSort {
        public List<int> num = new List<int>();

        public LinqSort() {
            Random rd = new Random(1);
            for (int i = 0; i < 100; i++)
            {
                var sort = rd.Next(0, 1001);
                num.Add(sort);
            }
        }
        public void Linqsort() {
            num = num.OrderByDescending(n => n).ToList();
        }
        public int LinqSum() {
            return num.Sum(n => n);
        }
        public double averange() {
            return num.Average(n => n);
        }
    }
}
